package com.dcsgo.socketPlay.server.game;

import com.dcsgo.socketPlay.server.Server;
import com.dcsgo.socketPlay.common.Ball;
import com.dcsgo.socketPlay.server.utils.MyRandom;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author DCSGO
 * @version 1.0
 * 管理所有玩家操作的小球
 */
public class BallManager {
    private static final HashMap<Integer, Ball> balls = new HashMap<>();

    public static Ball get(Integer key) {
        return balls.get(key);
    }

    public static void put(Integer key, Ball ball) {
        balls.put(key, ball);
    }

    public static void remove(Integer key) {
        balls.remove(key);
    }

    public static List<Ball> getBallList() {
        return new ArrayList<>(balls.values());
    }

    public static int[] getRandomPosition() {
        int ballSize = Integer.parseInt(Server.getGameProperties().getProperty("ballSize"));
        int maxWidth = Integer.parseInt(Server.getGameProperties().getProperty("gamePanelWidth"));
        int maxHeight = Integer.parseInt(Server.getGameProperties().getProperty("gamePanelHeight"));
        int x = MyRandom.getRandom(0, maxWidth - ballSize);
        int y = MyRandom.getRandom(0, maxHeight - ballSize);
        return new int[]{x, y};
    }
}
